//
//  TTLoginSingle.m
//  TaoTuo
//
//  Created by admin on 2019/8/16.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTLoginSingle.h"
#import "YBImageBrowser.h"

@implementation TTLoginSingle

+ (instancetype)sharedSingle
{
    static TTLoginSingle *single = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        single = [[self alloc] init];
        single.loginSubject = [RACSubject subject];
        single.shopCartSubject = [RACSubject subject];
        single.shopCartSelectBtnSubject = [RACSubject subject];
        single.addAddressSuccessSubject = [RACSubject subject];
        single.marketDic = [NSMutableDictionary dictionary];
        single.unLoginMarketDic = [NSMutableDictionary dictionary];
    });
    return single;
}

- (TTLoginModel *)loginModel
{
    if (!_loginModel) {
        _loginModel = [LLPasswordManagerUtilies getLoginUserInfo];
    }
    return _loginModel;
}

- (BOOL)isLogin
{
    TTLoginSingle *single = [TTLoginSingle sharedSingle];
    return single.loginModel != nil;
}

- (NSMutableDictionary *)marketDic
{
    if (_marketDic.count == 0) {
        NSDictionary *dic = [USER_DEFAULT objectForKey:marketDicKey];
        if (dic == nil) {
            _marketDic = [NSMutableDictionary dictionary];
        } else {
            _marketDic = dic.mutableCopy;
        }
    }
    return _marketDic;
}

- (NSMutableDictionary *)unLoginMarketDic
{
    if (_unLoginMarketDic.count == 0) {
        NSDictionary *dic = [USER_DEFAULT objectForKey:unLoginUserMarketDicKey];
        if (dic == nil) {
            _unLoginMarketDic = [NSMutableDictionary dictionary];
        } else {
            _unLoginMarketDic = dic.mutableCopy;
        }
    }
    return _unLoginMarketDic;
}


/**
 登录成功之后，设置用户数据
 */
+ (void)setupUserDataWithModel:(TTLoginModel *)model
{
    [TTLoginSingle sharedSingle].loginModel = model;
    
    [LLPasswordManagerUtilies saveLoginUserInfoWithModel:model];
}

// 清除用户信息
+ (void)deleteUserInfo
{
    [TTLoginSingle sharedSingle].loginModel = nil;
    [TTLoginSingle sharedSingle].userModel = nil;
    [TTLoginSingle sharedSingle].shopCartCount = 0;
    [TTLoginSingle sharedSingle].cartCodeArray = nil;
    
    [LLPasswordManagerUtilies deleteLoginUserInfo];
    
    UITabBarController *tabbarVC = [LLRouteTool getRootViewController];
    [tabbarVC.tabBar hiddenBadgeAtIndex:3];
    
}

// 保存金价开关状态
+ (void)saveGoldStatus
{
    if ([TTLoginSingle sharedSingle].isLogin) {
        NSMutableDictionary *dic = [TTLoginSingle sharedSingle].marketDic;
        [USER_DEFAULT setObject:dic forKey:marketDicKey];
    } else {
        NSMutableDictionary *unLoginDic = [TTLoginSingle sharedSingle].unLoginMarketDic;
        [USER_DEFAULT setObject:unLoginDic forKey:unLoginUserMarketDicKey];
    }
    [USER_DEFAULT synchronize];

}


- (NSDictionary *)routeTitleDic
{
    if (!_routeTitleDic) {
        _routeTitleDic = @{
                           @"11101" : @"女戒",
                           @"11102" : @"男戒",
                           @"11103" : @"对戒",
                           @"11104" : @"吊坠",
                           @"11105" : @"项链",
                           @"11106" : @"套链",
                           @"11107" : @"耳坠",
                           @"11108" : @"耳钉",
                           @"11109" : @"手镯",
                           @"11110" : @"手链",
                           @"11111" : @"耳线",
                           @"11112" : @"耳环",
                           };
    }
    return _routeTitleDic;
}

+ (void)lookCertificateWithUrlString:(NSString *)urlString
{
    if ([urlString hasSuffix:@".jpg"] || [urlString hasSuffix:@".png"] || [urlString hasSuffix:@".jpeg"]){
        YBIBImageData *data = [YBIBImageData new];
        data.imageURL = [NSURL URLWithString:urlString];
        YBImageBrowser *browser = [YBImageBrowser new];
        browser.dataSourceArray = @[data];
        [browser show];
    } else {
        LLWebViewController *webVC = [[LLWebViewController alloc] init];
        [webVC setUrlString:urlString htmlString:nil];
        [[LLRouteTool getCurrentNavigationController] pushViewController:webVC animated:YES];
    }
}


+ (int)findDiamondSizeWithSize:(CGFloat)diaSize
{
    if (diaSize >= 0 && diaSize <= 2) {
        return 0;
    } else if (diaSize >= 3 && diaSize <= 7) {
        return 5;
    } else if (diaSize >= 8 && diaSize <= 12) {
        return 10;
    } else if (diaSize >= 13 && diaSize <= 17) {
        return 15;
    } else if (diaSize >= 18 && diaSize <= 22) {
        return 20;
    } else if (diaSize >= 23 && diaSize <= 27) {
        return 25;
    } else if (diaSize >= 28 && diaSize <= 32) {
        return 30;
    } else if (diaSize >= 33 && diaSize <= 37) {
        return 35;
    } else if (diaSize >= 38 && diaSize <= 42) {
        return 40;
    } else if (diaSize >= 43 && diaSize <= 47) {
        return 45;
    } else if (diaSize >= 48 && diaSize <= 52) {
        return 50;
    } else if (diaSize >= 53 && diaSize <= 57) {
        return 55;
    } else if (diaSize >= 58 && diaSize <= 62) {
        return 60;
    } else if (diaSize >= 63 && diaSize <= 67) {
        return 65;
    } else if (diaSize >= 68 && diaSize <= 72) {
        return 70;
    } else if (diaSize >= 73 && diaSize <= 77) {
        return 75;
    } else if (diaSize >= 78 && diaSize <= 82) {
        return 80;
    } else if (diaSize >= 83 && diaSize <= 87) {
        return 85;
    } else if (diaSize >= 88 && diaSize <= 92) {
        return 90;
    } else if (diaSize >= 93 && diaSize <= 97) {
        return 95;
    } else if (diaSize >= 98 && diaSize <= 104) {
        return 100;
    } else if (diaSize >= 105 && diaSize <= 114) {
        return 110;
    } else if (diaSize >= 115 && diaSize <= 124) {
        return 120;
    } else if (diaSize >= 125 && diaSize <= 134) {
        return 130;
    } else if (diaSize >= 135 && diaSize <= 144) {
        return 140;
    } else if (diaSize >= 145 && diaSize <= 154) {
        return 150;
    } else if (diaSize >= 155 && diaSize <= 164) {
        return 160;
    } else if (diaSize >= 165 && diaSize <= 174) {
        return 170;
    } else if (diaSize >= 175 && diaSize <= 184) {
        return 180;
    } else if (diaSize >= 185 && diaSize <= 194) {
        return 190;
    } else if (diaSize >= 195 && diaSize <= 204) {
        return 200;
    } else if (diaSize >= 205 && diaSize <= 214) {
        return 210;
    } else if (diaSize >= 215 && diaSize <= 224) {
        return 220;
    } else if (diaSize >= 225 && diaSize <= 234) {
        return 230;
    } else if (diaSize >= 235 && diaSize <= 244) {
        return 240;
    } else if (diaSize >= 245 && diaSize <= 254) {
        return 250;
    } else if (diaSize >= 255 && diaSize <= 264) {
        return 260;
    } else if (diaSize >= 265 && diaSize <= 274) {
        return 270;
    } else if (diaSize >= 275 && diaSize <= 284) {
        return 280;
    } else if (diaSize >= 285 && diaSize <= 294) {
        return 290;
    } else if (diaSize >= 295 && diaSize <= 304) {
        return 300;
    } else if (diaSize >= 305 && diaSize <= 314) {
        return 310;
    } else if (diaSize >= 315 && diaSize <= 324) {
        return 320;
    } else if (diaSize >= 325 && diaSize <= 334) {
        return 330;
    } else if (diaSize >= 335 && diaSize <= 344) {
        return 340;
    } else if (diaSize >= 345 && diaSize <= 354) {
        return 350;
    } else if (diaSize >= 355 && diaSize <= 364) {
        return 360;
    } else if (diaSize >= 365 && diaSize <= 374) {
        return 370;
    } else if (diaSize >= 375 && diaSize <= 384) {
        return 380;
    } else if (diaSize >= 385 && diaSize <= 394) {
        return 390;
    } else if (diaSize >= 395 && diaSize <= 404) {
        return 400;
    } else if (diaSize >= 405 && diaSize <= 414) {
        return 410;
    } else if (diaSize >= 415 && diaSize <= 424) {
        return 420;
    } else if (diaSize >= 425 && diaSize <= 434) {
        return 430;
    } else if (diaSize >= 435 && diaSize <= 444) {
        return 440;
    } else if (diaSize >= 445 && diaSize <= 454) {
        return 450;
    } else if (diaSize >= 455 && diaSize <= 464) {
        return 460;
    } else if (diaSize >= 465 && diaSize <= 474) {
        return 470;
    } else if (diaSize >= 475 && diaSize <= 484) {
        return 480;
    } else if (diaSize >= 485 && diaSize <= 494) {
        return 490;
    } else if (diaSize >= 495 && diaSize <= 504) {
        return 500;
    } else if (diaSize >= 505 && diaSize <= 514) {
        return 510;
    } else if (diaSize >= 515 && diaSize <= 524) {
        return 520;
    } else if (diaSize >= 525 && diaSize <= 534) {
        return 530;
    } else if (diaSize >= 535 && diaSize <= 544) {
        return 540;
    } else if (diaSize >= 545 && diaSize <= 554) {
        return 550;
    } else if (diaSize >= 555 && diaSize <= 564) {
        return 560;
    } else if (diaSize >= 565 && diaSize <= 574) {
        return 570;
    } else if (diaSize >= 575 && diaSize <= 584) {
        return 580;
    } else if (diaSize >= 585 && diaSize <= 594) {
        return 590;
    } else if (diaSize >= 595 && diaSize <= 604) {
        return 600;
    } else if (diaSize >= 605 && diaSize <= 614) {
        return 610;
    } else if (diaSize >= 615 && diaSize <= 624) {
        return 620;
    } else if (diaSize >= 625 && diaSize <= 634) {
        return 630;
    } else if (diaSize >= 635 && diaSize <= 644) {
        return 640;
    } else if (diaSize >= 645 && diaSize <= 654) {
        return 650;
    } else if (diaSize >= 655 && diaSize <= 664) {
        return 660;
    } else if (diaSize >= 665 && diaSize <= 674) {
        return 670;
    } else if (diaSize >= 675 && diaSize <= 684) {
        return 680;
    } else if (diaSize >= 685 && diaSize <= 694) {
        return 690;
    } else if (diaSize >= 695 && diaSize <= 704) {
        return 700;
    } else if (diaSize >= 705 && diaSize <= 714) {
        return 710;
    } else if (diaSize >= 715 && diaSize <= 724) {
        return 720;
    } else if (diaSize >= 725 && diaSize <= 734) {
        return 730;
    } else if (diaSize >= 735 && diaSize <= 744) {
        return 740;
    } else if (diaSize >= 745 && diaSize <= 754) {
        return 750;
    } else if (diaSize >= 755 && diaSize <= 764) {
        return 760;
    } else if (diaSize >= 765 && diaSize <= 774) {
        return 770;
    } else if (diaSize >= 775 && diaSize <= 784) {
        return 780;
    } else if (diaSize >= 785 && diaSize <= 794) {
        return 790;
    } else if (diaSize >= 795 && diaSize <= 804) {
        return 800;
    } else if (diaSize >= 805 && diaSize <= 814) {
        return 810;
    } else if (diaSize >= 815 && diaSize <= 824) {
        return 820;
    } else if (diaSize >= 825 && diaSize <= 834) {
        return 830;
    } else if (diaSize >= 835 && diaSize <= 844) {
        return 840;
    } else if (diaSize >= 845 && diaSize <= 854) {
        return 850;
    } else if (diaSize >= 855 && diaSize <= 864) {
        return 860;
    } else if (diaSize >= 865 && diaSize <= 874) {
        return 870;
    } else if (diaSize >= 875 && diaSize <= 884) {
        return 880;
    } else if (diaSize >= 885 && diaSize <= 894) {
        return 890;
    } else if (diaSize >= 895 && diaSize <= 904) {
        return 900;
    } else if (diaSize >= 905 && diaSize <= 914) {
        return 910;
    } else if (diaSize >= 915 && diaSize <= 924) {
        return 920;
    } else if (diaSize >= 925 && diaSize <= 934) {
        return 930;
    } else if (diaSize >= 935 && diaSize <= 944) {
        return 940;
    } else if (diaSize >= 945 && diaSize <= 954) {
        return 950;
    } else if (diaSize >= 955 && diaSize <= 964) {
        return 960;
    } else if (diaSize >= 965 && diaSize <= 974) {
        return 970;
    } else if (diaSize >= 975 && diaSize <= 984) {
        return 980;
    } else if (diaSize >= 985 && diaSize <= 994) {
        return 990;
    } else if (diaSize >= 995 && diaSize <= 1004) {
        return 1000;
    } else if (diaSize >= 1005 && diaSize <= 9999) {
        return 5000;
    } else {
        return 5000;
    }
    
    
}




@end
